package unwdmi.connector;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class ClientConnector implements Runnable {

	private Socket clientSocket;
	private PrintWriter out;
	private BufferedReader in;
	
	
	public ClientConnector(Socket clientSocket){
		try {
			this.clientSocket = clientSocket;
			in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			out = new PrintWriter(clientSocket.getOutputStream(), true);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void run() {
		boolean running = true;
		String command = "";
		while(running){
			out.println("Welcome, please enter a City name to get information about it: ");
			try {
				command = in.readLine();
				if(command.equals("exit")){
					out.println("Bye bye!");
					System.out.println("Client disconnected!");
					clientSocket.close();
					running = false;
				}else{
					out.println("Trying to find information for city: " + command);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}

}
